#include "k4form.h"
#include "ui_k4form.h"
#include <QKeyEvent>
#include <QSerialPort>
#include <QDebug>
#include "uart.h"

k4Form::k4Form(QWidget *parent) :
  QWidget(parent),
  ui(new Ui::k4Form)
{
  ui->setupUi(this);
//  this->setStyleSheet("background-color: rgb(0, 186, 238);");
  box_sel=NULL;
  QImage *img=GetLogo();
  if(img!=NULL)
      ui->label_Logo->setPixmap(QPixmap::fromImage(*img).scaled(ui->label_Logo->size()));
}

k4Form::~k4Form()
{
  delete ui;
    //serial.close();
}

void k4Form::keyPressEvent(QKeyEvent *event)
{
    int key=event->key();
  qDebug()<< key;
//  printf("key= %d\n",key);
    if(key==Qt::Key_F12||key==Qt::Key_Exit)
    {
        if(ShowPreWin())
            this->hide();
    }
    else
        if(ShowWin(key,0))
            this->hide();
}

void k4Form::on_checkBox_clicked()
{
    SelBox(ui->checkBox);
    sendUartCmd_timing(k4_30);
}

void k4Form::on_checkBox_5_clicked()
{
    SelBox(ui->checkBox_5);
    sendUartCmd_timing(k4_60);
}

void k4Form::on_checkBox_2_clicked()
{
    SelBox(ui->checkBox_2);
    sendUartCmd_timing(k4_2997);
}

void k4Form::on_checkBox_3_clicked()
{
    SelBox(ui->checkBox_3);
    sendUartCmd_timing(k4_25);
}

void k4Form::on_checkBox_4_clicked()
{
    SelBox(ui->checkBox_4);
    sendUartCmd_timing(k4_24);
}

void k4Form::on_checkBox_6_clicked()
{
    SelBox(ui->checkBox_6);
    sendUartCmd_timing(k4_5994);
}

void k4Form::on_checkBox_7_clicked()
{
    SelBox(ui->checkBox_7);
    sendUartCmd_timing(k4_50);
}

void k4Form::on_checkBox_8_clicked()
{
    SelBox(ui->checkBox_8);
    sendUartCmd_timing(k4_23);
}

void k4Form::on_checkBox_9_clicked()
{
    SelBox(ui->checkBox_9);
    sendUartCmd_timing(k4_48);
}

void k4Form::on_checkBox_11_clicked()
{
    SelBox(ui->checkBox_11);
    sendUartCmd_timing(k4_47);
}

void k4Form::on_checkBox_12_clicked()
{
    SelBox(ui->checkBox_12);
    sendUartCmd_timing(k4_100);
}

void k4Form::on_checkBox_13_clicked()
{
    SelBox(ui->checkBox_13);
    sendUartCmd_timing(k4_120);
}

void k4Form::on_checkBox_10_clicked()
{
    SelBox(ui->checkBox_10);
    sendUartCmd_timing(k4_119);
}
